package org.example.itext;

import com.itextpdf.text.pdf.PdfDictionary;
import com.itextpdf.text.pdf.PdfName;
import com.itextpdf.text.pdf.security.ExternalSignatureContainer;
import org.example.jida.JiDaSigUtil;

import java.io.IOException;
import java.io.InputStream;
import java.security.GeneralSecurityException;

public class JidaHSMExternalSignatureContainer implements ExternalSignatureContainer {

    @Override
    public byte[] sign(InputStream data) throws GeneralSecurityException {
        try {
            return JiDaSigUtil.JITSign(data);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void modifySigningDictionary(PdfDictionary signDic) {
        // 可以在这里修改签名字典，例如添加额外的信息
        signDic.put(PdfName.FFILTER, PdfName.ADOBE_PPKLITE);
        //signDic.put(PdfName.SUBFILTER,PdfName.ADBE_GM_DETACHED);
        signDic.put(PdfName.SUBFILTER, PdfName.ADBE_PKCS7_DETACHED);
    }

}
